# 接口调用
import requests, json

# 热门视频榜单
appKey = '96a455a4618adafe39454e4861dce201'
apiUrl = 'http://apis.juhe.cn/fapig/douyin/billboard'
size = 50
apitype = "hot_video"

result = requests.get(url=apiUrl, params={"key": appKey, "type": apitype, "size": size})
# result = requests.post(url=apiUrl, data={"key": appKey, "type": type, "size": size})
# data = result.json() # text 文本信息  content 原始数据  json json数据(这个方法会直接将json的数据转换为字典)
# for data_result in data["result"]:
#     print(data_result["title"],data_result["share_url"])

data = result.text
data = json.dumps(json.loads(data), indent="  ", ensure_ascii=False)
print(data)


# json转换
'''
import json
# 字典转换json数据
dict1 = {"姓名":"老王","年龄": 18, "工作": "司机"}
json_result = json.dumps(dict1, ensure_ascii=False, indent="  ")
print(json_result)

# json 数据转换字典
dict_result = json.loads(json_result)
print(dict_result)
print(type(dict_result))
'''